home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / cpp_libs / sos3-2.lha / include / knl_ext.h < prev    next >
C/C++ Source or Header  |  1992-01-23  |  7KB  |  199 lines

  1. /* --------------------------------------------------------------------------
  2.  * Copyright 1992 by Forschungszentrum Informatik (FZI)
  3.  *
  4.  * You can use and distribute this software under the terms of the licence
  5.  * you should have received along with this program.
  6.  * If not or if you want additional information, write to
  7.  * Forschungszentrum Informatik, "STONE", Haid-und-Neu-Strasse 10-14,
  8.  * D-7500 Karlsruhe 1, Germany.
  9.  * --------------------------------------------------------------------------
  10.  */
  11. #ifndef KNLEXTH
  12. #define KNLEXTH 1
  13.  
  14. #include <string.h>
  15. #include <libc.h>
  16. #include "psm.h"
  17.  
  18. class sos_Object;
  19. class sos_Object_Array;
  20.  
  21. // *****************************  sos_Short  *********************************
  22.  
  23. typedef short sos_Short;
  24.  
  25. // *****************************  sos_Int  *********************************
  26.  
  27. typedef int sos_Int;
  28.  
  29. #define INT_SIZE 4
  30. inline void bcopy_from_sos_Int (void *i, void *c)
  31. {  *(sos_Int *)c = *(sos_Int *)i; }
  32. inline void bcopy_to_sos_Int (void *i, void *c)
  33. {  *(sos_Int *)i = *(sos_Int *)c; }
  34. sos_String make_string_from_sos_Int_object (sos_Object);
  35. sos_Object make_sos_Int_object_from_string (sos_String);
  36.  
  37. // *****************************  sos_Char  ********************************
  38.  
  39. typedef char sos_Char;
  40.  
  41. #define CHAR_SIZE 1
  42. inline void bcopy_from_sos_Char (void *ch, void *c)
  43. {  *(sos_Char*)c = *(sos_Char*)ch; }
  44. inline void bcopy_to_sos_Char (void *ch, void *c)
  45. {  *(sos_Char*)ch = *(sos_Char*)c; }
  46. sos_String make_string_from_sos_Char_object (sos_Object);
  47. sos_Object make_sos_Char_object_from_string (sos_String);
  48.  
  49. // **************************  sos_Pointer  ****************************
  50.  
  51. typedef void *sos_Pointer;
  52.  
  53. #define POINTER_SIZE 4
  54. inline void bcopy_from_sos_Pointer (void *p, void *c)
  55. {  *(sos_Pointer *)c = *(sos_Pointer *)p; }
  56. inline void bcopy_to_sos_Pointer (void *p, void *c)
  57. {  *(sos_Pointer *)p = *(sos_Pointer *)c; }
  58. sos_String make_string_from_sos_Pointer_object (sos_Object);
  59. sos_Object make_sos_Pointer_object_from_string (sos_String);
  60.  
  61. // ****************************  sos_Offset ********************************
  62.  
  63. // sos_Offset is declared in "psm.h"
  64.  
  65. #define SOS_OFFSET_SIZE 4
  66. inline void bcopy_from_sos_Offset (void *o, void *c)
  67. {  *(sos_Offset *)c = *(sos_Offset *)o; }
  68. inline void bcopy_to_sos_Offset (void *o, void *c)
  69. {  *(sos_Offset *)o = *(sos_Offset *)c; }
  70. sos_String make_string_from_sos_Offset_object (sos_Object);
  71. sos_Object make_sos_Offset_object_from_string (sos_String);
  72.  
  73. // ***************************  sos_Container  *****************************
  74.  
  75. // sos_Container is declared in "psm.h"
  76.  
  77. #define SOS_CONTAINER_SIZE 4
  78. inline void bcopy_from_sos_Container (void *ct, void *c)
  79. {  *(sos_Container *)c = *(sos_Container *)ct; }
  80. inline void bcopy_to_sos_Container (void *ct, void *c)
  81. {  *(sos_Container *)ct = *(sos_Container *)c; }
  82. sos_String make_string_from_sos_Container_object (sos_Object);
  83. sos_Object make_sos_Container_object_from_string (sos_String);
  84.  
  85. // ****************************  sos_Cstring  *******************************
  86.  
  87. typedef char *sos_Cstring;
  88.  
  89. #define SOS_STRING_SIZE 4
  90. inline void bcopy_from_sos_Cstring (void *s, void *c)
  91. {  *(sos_Cstring *)c = *(sos_Cstring *)s; }
  92. inline void bcopy_to_sos_Cstring (void *s, void *c)
  93. {  *(sos_Cstring *)s = *(sos_Cstring *)c; }
  94. sos_String make_string_from_sos_Cstring_object (sos_Object);
  95. sos_Object make_sos_Cstring_object_from_string (sos_String);
  96.  
  97. // ******************************  sos_Id **********************************
  98.  
  99. class sos_Id
  100. {
  101.    sos_Container ct;
  102.    sos_Offset    os;
  103. public:
  104.    sos_Container container () {  return ct; }
  105.    sos_Offset    offset ()    {  return os; }
  106.  
  107.    static sos_Id make (sos_Container ct, sos_Offset os)
  108.    {  sos_Id id; id.ct=ct; id.os=os; return id;}
  109.  
  110.    sos_Bool operator== (sos_Id id) { return (sos_Bool) (ct == id.ct && os == id.os);}
  111.    sos_Bool operator!= (sos_Id id) { return (sos_Bool) (ct != id.ct || os != id.os);}
  112.  
  113.    sos_Id get_type_id ();
  114.    void   set_type_id (sos_Id tp);
  115. };
  116.  
  117. #define SOS_ID_SIZE 8
  118. inline void bcopy_from_sos_Id (void *i, void *c)
  119. {  *(sos_Id *)c = *(sos_Id *)i; }
  120. inline void bcopy_to_sos_Id (void *i, void *c)
  121. {  *(sos_Id *)i = *(sos_Id *)c; }
  122. sos_String make_string_from_sos_Id_object (sos_Object);
  123. sos_Object make_sos_Id_object_from_string (sos_String);
  124.  
  125.  
  126. // ***************************  sos_Typed_id *******************************
  127.  
  128. class sos_Type;
  129.  
  130. class sos_Typed_id
  131. {  sos_Id id;
  132.    sos_Id tp;
  133. public:
  134.    static sos_Typed_id make (sos_Id id, sos_Id tp)
  135.    {  sos_Typed_id tpid; tpid.id=id; tpid.tp=tp; return tpid;}
  136.  
  137.    sos_Id       get_id () { return id; }
  138.    sos_Id       get_tp () { return tp; }
  139.  
  140.    sos_Container container () {  return id.container(); }
  141.    sos_Offset    offset ()    {  return id.offset(); }
  142.  
  143.    sos_Bool operator== (sos_Typed_id &tpid)
  144.    { return (sos_Bool) (id == tpid.id && tp == tpid.tp); }
  145.    sos_Bool operator!= (sos_Typed_id &tpid)
  146.    { return (sos_Bool) (id != tpid.id || tp != tpid.tp); }
  147.  
  148.    static sos_Typed_id allocate (sos_Type, sos_Container);
  149.    static sos_Typed_id allocate (sos_Type, sos_Container, sos_Int);
  150.  
  151.    static sos_Typed_id make (sos_Id);
  152.  
  153. }; // ** sos_Typed_id **
  154.  
  155. #define SOS_TYPED_ID_SIZE 16
  156. inline void bcopy_from_sos_Typed_id (void *tpid, void *c)
  157. {  *(sos_Typed_id *)c = *(sos_Typed_id *)tpid; }
  158. inline void bcopy_to_sos_Typed_id (void *tpid, void *c)
  159. {  *(sos_Typed_id *)tpid = *(sos_Typed_id *)c; }
  160.  
  161. // ***************************  sos_Root_class *****************************
  162.  
  163. class sos_Root_class
  164. {
  165. protected:
  166.    sos_Typed_id _tpid;
  167. public:
  168.    sos_Typed_id typed_id() {return _tpid;}
  169.    sos_Container container() {return _tpid.container();}
  170.    sos_Offset offset() {return _tpid.offset();}
  171. };
  172.  
  173. // ************************* local offset handling *************************
  174.  
  175. extern sos_Typed_id sos_make_local_typed_id (sos_Offset, sos_Container);
  176. extern sos_Offset   sos_local_offset        (sos_Object, sos_Container);
  177.  
  178. // *********************** scalar object representation ********************
  179.  
  180. extern sos_Scalar_object sos_object_from_extern (void* addr,
  181.                          void bcopy_from (void*,void*),
  182.                          sos_Id tp);
  183. extern void              sos_extern_from_object (void* addr,
  184.                          sos_Object o,
  185.                          void bcopy_to (void*,void*),
  186.                          sos_Id tp);
  187. extern sos_Int      sos_Int_from_enum (sos_Object,sos_Type);
  188. extern sos_Scalar_object sos_enum_from_sos_Int (sos_Int,sos_Type);
  189.  
  190. // ************************** type representation **************************
  191.  
  192. extern sos_Type   sos_type_object (sos_Id,sos_Id);
  193.  
  194. // ***********************  Auxiliary Operations ***************************
  195.  
  196. extern sos_Object NO_OBJECT;
  197.  
  198. #endif
  199.